var isMail = false;
var isPwd = false;
var isRepeat = false;

$(document).ready(function() {
	$("#reg_mail").bind("input propertychange", function() {
		var response = $.ajax({
			url : "/mailCheck.action",
			async : false,
			type:"GET"
		});
		if (response == "true") {
			isRepeat=true;
			var msg = "输入的邮箱名已经被注册了";
			$("#reg_mail_msg").html($("#reg_mail_msg").html()+msg);
		}
	});
	$("#login_button").click(function() {
		var mail = $("#inputEmail").val();
		var pwd = $("#inputPassword").val();
		emailCheck(mail);
		pwdCheck(pwd);
		if(isMail&&isPwd){
			//alert(isMail+'-----'+isPwd);
			document.loginForm.submit();
		}else{
			var a = document.getElementById("login_msg");
			a.innerHTML = "请输入正确登陆信息";
			return;
		}
	});
});
/**
 * Check email format
 */
function emailCheck(mail) {
	//alert(mail);
	var pattern = /^([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
	if (!pattern.test(mail)) {
		var a = document.getElementById("login_msg");
		a.innerHTML = "请输入正确的邮箱地址";
		$("#inputEmail").focus();
	} else {
		var a = document.getElementById("login_msg");
		a.innerHTML = "";
		isMail=true;
	}
	return;
}
function pwdCheck(pwd) {
	//alert(pwd);
	if (pwd.length < 3) {
		var a = document.getElementById("login_msg");
		a.innerHTML = "密码长度太短，请继续输入";
		$("#inputPassword").focus();
	} else {
		var a = document.getElementById("login_msg");
		a.innerHTML = "";
		isPwd=true;
	}
	return;
}
